
Page({
  data: {
    testArr: true
  },
  transaction() {
    const { testUrl } = getApp().globalData

    if(my.canIUse('checkBeforeAddOrder')) {
      my.checkBeforeAddOrder({
        success({ requireOrder, sceneId, sourceId }) {
          console.log(requireOrder, sceneId, sourceId);
          my.request({
            url: `${testUrl}/test/orderCreate`,
            method: 'POST',
            data: {
              requireOrder, 
              sceneId, 
              sourceId
            },
            success: (res) => {
              console.log(res, 'res');
            }
          })
        },
        fail({ errorMessage }) {
          my.showToast({
            type: 'none',
            content: errorMessage,
            duration: 3000
          })
        },
        complete() {},
      })
    } else {
      my.showToast({
        type: 'none',
        content: '当前客户端版本不支持，更新后再来吧~',
        duration: 3000
      })
    }
  },

  getAddress() {
    my.chooseLocation({
      success: function(res) {
        console.log(res);
      },
      fail: function(err) {
        console.log(err);
      }
    });
  },

  jumpNoSesameRentMachine() {
    my.navigateTo({
      url: '/page/rent/h5/noSesameRentMachine/noSesameRentMachine'
    })
  },


  clickTop() {
    my.pageScrollTo({
      selector: ".title"
    })
  },

  // 获取位置信息
  getLocation() {
    const app = getApp()
    app.getLocation()
  },
  // 开启会员卡
  onOpenCard() {
    var plugin = requirePlugin("alipassToolKit") // 引用名称需与 app.json 中定义名称相同
    let params = {
      cardParams:{//开卡入参，
        templateId:'20230228000000004431380000300814', // 开卡的卡模板ID
        templateAppId:'2021002129611863', // 卡模板ID 所关联的 AppId
        outString:'xxx',//商家自定义透传信息
        pageType:'half',//默认是 half
        
      },  
      callback: function (res) {
          console.log('======', res)
          if (res.success === true) {
            console.log('----- success')
          }
        }
      }
     plugin.openCard(params);// 接口参数说明如下
    },
    jumpPage(e) {
      const { url } = e.target.dataset
      my.navigateTo({
        url
      })
    },
    jumpH5Page() {
      my.ap.openURL({
        url: 'https://www.ddzuji.cn/topic/alipay/h5/greenEnergy/index.html#/'
      })
    }
});